import collections
class Solution(object):
    def leastBricks(self, wall):
        d = collections.defaultdict(int)
        d[0] = 0
        n = len(wall)
        for t in wall:
            now = 0
            for q in t[:-1]:
                now += q
                d[now] += 1
        return n - max(d.values())